package com.hw.paltfrom.service.casemain;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hw.paltfrom.mapper.*;
import com.hw.paltfrom.service.doncutor.BaseWorkflowService;
import com.hw.paltfrom.service.doncutor.CommandWorkflowService;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.pack.ResponseResult;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.PageUtils;
import com.hw.paltfrom.utils.ResponeResultUtil;
import com.hw.paltfrom.vo.StationCaseMainVo;
import com.hw.paltfrom.exception.HWSystemException;
import com.hw.paltfrom.pojo.*;
import com.hw.paltfrom.utils.RandomNumberUtil;
import com.hw.paltfrom.vo.FileInfo;
import com.hw.paltfrom.vo.StationCaseFileVo;
import com.hw.paltfrom.vo.StepInfoVO;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StationCasemainServer {


    @Autowired //案件主表
    private HwCaseMainMapper hwCaseMainMapper;
    @Autowired  //案件站点办理  HW_Case_SiteOper
    private HwCaseSiteoperMapper hwCaseSiteoperMapper;
    @Autowired //HW_Case_PoliceOper 案件交警执法
    private HwCasePoliceoperMapper hwCasePoliceoperMapper;
    @Autowired //源头倒查表 ：HW_Case_SrcCom
    private HwCaseSrccomMapper hwCaseSrccomMapper;
    @Autowired//  //HW_Case_FileConfig  文书基础配置表
    private HwCaseFileconfigMapper hwCaseFileconfigMapper;
    @Autowired //HW_Case_File 案件文书上传表
    private HwCaseFileMapper hwCaseFileMapper;
    @Autowired //// 创建基础工作流的接口
    private BaseWorkflowService baseWorkflowService;
    @Autowired   // // 向各阶段审批操作过程表插入数据 接口
    private CommandWorkflowService commandWorkflowService;

    @Autowired //附件表
    private HwBaseAnnexesfileMapper hwBaseAnnexesfileMapper;

    public Map<String, Object> query(StationCaseMainVo vo) {
        Integer pageNum = vo.getPageNum();
        Integer pageSize = vo.getPageSize();

        // 所属单位
        String overruncode = vo.getfOverruncode();
        // 办理阶段
        String F_AJ_CrtStep = vo.getfAjCrtstep();
        // 车牌号
        String F_CL_TruckNo = vo.getfClTruckno();
        
        // 范围
        String compare = vo.getCompare();
        // 超限吨数
        Double F_CL_OverWeight = vo.getfClOverweight();
        
//        轴数范围
        String zscompare = vo.getZscompare();
        // 轴数
        String F_CL_Axis = vo.getfClAxis();
        
        // 静态称重
        Double F_CL_TotalWeight = vo.getfClTotalweight();
        // 静态称重范围
        String czcompare = vo.getCzcompare();
      
        // 检测开始时间
        Timestamp StartTime = null;
        // 检测结束时间
        Timestamp EndTime = null;
        // 责任倒查
        Integer F_AJ_Investigate = vo.getfAjInvestigate();
        // 交警处罚
        Integer F_AJ_Police = vo.getfAjPolice();
        // 放行类型
        Integer F_AJ_GoState = vo.getfAjGostate();

        if (vo.getStartTime() == null) {
            if (vo.getEndTime() == null) {
            } else {
                return ResponseResult.fail(HWSystemCode.PARAMS_ERROR);
            }
        } else {
            if (vo.getEndTime() != null) {
                StartTime = Timestamp.valueOf(vo.getStartTime());
                EndTime = Timestamp.valueOf(vo.getEndTime());
            } else {
                return ResponseResult.fail(HWSystemCode.PARAMS_ERROR);
            }
        }

        Wrapper<HwCaseMain> wrapper = new EntityWrapper<HwCaseMain>();

        if (StringUtils.isNotBlank(overruncode)) {
            wrapper.eq("F_OverrunCode", overruncode);
        }
        if (StringUtils.isNotBlank(F_AJ_CrtStep)) {
            wrapper.eq("F_AJ_CrtStep", F_AJ_CrtStep);
        } else {
            wrapper.ne("F_AJ_CrtStep", "07");
        }
        if (StringUtils.isNotBlank(F_CL_TruckNo)) {
            wrapper.like("F_CL_TruckNo", F_CL_TruckNo);
        }
        if (F_CL_OverWeight != null) {
            switch (compare) {
                case "1":
                    wrapper.ge("F_CL_OverWeight", F_CL_OverWeight);
                    break;
                case "0":
                    wrapper.eq("F_CL_OverWeight", F_CL_OverWeight);
                    break;
                case "-1":
                    wrapper.le("F_CL_OverWeight", F_CL_OverWeight);
                    break;
            }
        }
        if (F_CL_TotalWeight != null) {
        	switch (czcompare) {
            case "1":
                wrapper.ge("F_CL_TotalWeight", F_CL_TotalWeight);
                break;
            case "0":
                wrapper.eq("F_CL_TotalWeight", F_CL_TotalWeight);
                break;
            case "-1":
                wrapper.le("F_CL_TotalWeight", F_CL_TotalWeight);
                break;
        }
        	
        	
//            wrapper.eq("F_CL_TotalWeight", F_CL_TotalWeight);
        }
        if (StringUtils.isNotBlank(F_CL_Axis)) {
        	switch (zscompare) {
            case "1":
                wrapper.ge("F_CL_Axis", F_CL_Axis);
                break;
            case "0":
                wrapper.eq("F_CL_Axis", F_CL_Axis);
                break;
            case "-1":
                wrapper.le("F_CL_Axis", F_CL_Axis);
                break;
        }
        	
//            wrapper.eq("F_CL_Axis", F_CL_Axis);
        }
        if (F_AJ_Investigate != null) {
            wrapper.eq("F_AJ_Investigate", F_AJ_Investigate);
        }
        if (F_AJ_Police != null) {
            wrapper.eq("F_AJ_Police", F_AJ_Police);
        }
        if (F_AJ_GoState != null) {
            wrapper.eq("F_AJ_GoState", F_AJ_GoState);
        }

        if (StartTime != null && EndTime != null) {
            wrapper.between("F_CL_CheckTime", StartTime, EndTime);

        }
        List<HwCaseMain> list = hwCaseMainMapper.selectList(wrapper);
        PageUtils<Object> pageUtils = new PageUtils<Object>(pageNum, pageSize);
        List<Object> result = new ArrayList<>();
        for (HwCaseMain hm : list) {
//			private Integer laButton;
//			private Integer xgButton;
//			private Integer wsscButton;
//			private Integer fxqrButton;
//			private Integer fxsmButton;
            String crtstep = hm.getfAjCrtstep();
            Integer gostate = hm.getfAjGostate();
            Map<String, Object> fkmap = (Map<String, Object>) JSON.toJSON(hm);
//			立案按钮显示条件
            if ("01".equals(crtstep)) {
                fkmap.put("laButton", "1");
            } else {
                fkmap.put("laButton", "0");
            }
//			修改按钮显示条件
            if ("02".equals(crtstep)) {
                fkmap.put("xgButton", "1");
            } else {
                fkmap.put("xgButton", "0");
            }
//			文书上传按钮显示条件
            if (gostate == 0 && ("02".equals(crtstep) || "03".equals(crtstep) || "04".equals(crtstep) || "05".equals(crtstep))) {
                fkmap.put("wsscButton", "1");
            } else {
                fkmap.put("wsscButton", "0");
            }
//			放行确认按钮显示条件

            if ("05".equals(crtstep) && gostate == 0) {
                fkmap.put("fxqrButton", "1");
            } else {
                fkmap.put("fxqrButton", "0");
            }
//			放行说明显示条件
            if ("05".equals(crtstep) && gostate == 1) {
                fkmap.put("fxsmButton", "1");
            } else {
                fkmap.put("fxsmButton", "0");
            }

            result.add(fkmap);
        }
        Object pageResult = pageUtils.getPageResult(result);
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, pageResult);
    }

    /**
     * 超限站（执法监管）---立案
     *
     * @param
     * @return put on record
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class, RuntimeException.class,
            HWSystemException.class})
    public Map<String, Object> putOnRecord(StationCaseMainVo sCMV) {
        //F_CaseId主键ID
        String fCaseid = sCMV.getVo().getfCaseid();
        //称重Id
        String fOverruncode = sCMV.getVo().getfOverrunid();
        //F_AJ_CrtStep='03'立案提交  和 F_AJ_CrtStep='02' 案件暂存
        String fAjCrtstep = sCMV.getVo().getfAjCrtstep();
        //立案提交
        sCMV.getVo().setFlowCode(sCMV.getVo().getfAjCasetype());
        if ("03".equals(fAjCrtstep)) {
            String getfAjCasecode = sCMV.getVo().getFlowCode();
            //fAjCreatetime
            long beginlong = new Long(sCMV.getfAjCreatetime());
            HwBaseWorkflow presentWorkflow = baseWorkflowService.getPresentWorkflow("02", getfAjCasecode);
            sCMV.getVo().setfAjCrtstep(presentWorkflow.getWorkflowNextcode());
            sCMV.getVo().setFAjCreatetime(new Timestamp(beginlong));//new Timestamp(System.currentTimeMillis())
            if ("GR".equals(sCMV.getVo().getfCzOrgtype())) {
                sCMV.getVo().setfCzParty(sCMV.getVo().getfPartyname());
                sCMV.getVo().setfAjOwner("公民");

            }
            if ("GS".equals(sCMV.getVo().getfCzOrgtype())) { //单位
                sCMV.getVo().setfAjOwner("法人及其它组织");
                sCMV.getVo().setfCzParty(sCMV.getVo().getfCompanyname());
            }
            //修改立案的内容
            Wrapper<HwCaseMain> stationStorywrapper = new EntityWrapper<HwCaseMain>();
            stationStorywrapper.eq("F_CaseId", fCaseid).eq("F_OverrunID", fOverruncode);
            Integer update = hwCaseMainMapper.update(sCMV.getVo(), stationStorywrapper);
            if (update != 0) {
                HwCaseSiteoper hwCaseSiteoper = new HwCaseSiteoper();
                Wrapper<HwCaseSiteoper> caseSiteOPerWrapper = new EntityWrapper<HwCaseSiteoper>();
                caseSiteOPerWrapper.eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                List<HwCaseSiteoper> hwCaseSiteopers = hwCaseSiteoperMapper.selectList(caseSiteOPerWrapper);
                //案件站点办理
                String code = RandomNumberUtil.getNumber();
                hwCaseSiteoper.setfOverrunid(fOverruncode);// 称重Id
                hwCaseSiteoper.setfMainid(fCaseid);//案件Id
                //没有添加
                if (hwCaseSiteopers.size() == 0) {
                    hwCaseSiteoper.setfSiteoperid(code); //
                    //情况说明附件 不必传
                    List<FileInfo> fileInfoList = sCMV.getfFirstviewannex();
                    String FileName = "初检单附件";
                    String universal = universal(fileInfoList, FileName, fCaseid);
                    hwCaseSiteoper.setfFirstviewannex(universal);//初检单 sCMV.getfFirstviewannex()
                    List<FileInfo> fileInfo = sCMV.getfReviewannex();
                    String FileNames = "复检单附件";
                    String universas = universal(fileInfo, FileNames, fCaseid);
                    hwCaseSiteoper.setfReviewannex(universas);//复检单 sCMV.getfReviewannex()
                    List<FileInfo> fileInfos = sCMV.getfTranannex();
                    String FileNamess = "移交单附件";
                    String universass = universal(fileInfos, FileNamess, fCaseid);
                    hwCaseSiteoper.setfTranannex(universass);// 移交单 sCMV.getfTranannex()
                    List<FileInfo> fileInfos1 = sCMV.getfCopyannex();
                    String FileNamesss = "抄送单附件";
                    String universasss = universal(fileInfos1, FileNamesss, fCaseid);
                    hwCaseSiteoper.setfCopyannex(universasss);//抄送单 sCMV.getfCopyannex()
                    List<FileInfo> fileInfos2 = sCMV.getfFourlicannex();
                    String FileNamessss = "四证照片附件";
                    String universassss = universal(fileInfos2, FileNamessss, fCaseid);
                    hwCaseSiteoper.setfFourlicannex(universassss); //“四证”照片 sCMV.getfFourlicannex()
                    List<FileInfo> fileInfos3 = sCMV.getfGoodsannex();
                    if (fileInfos3.size() != 0) {
                        String FileNamehs = "货运单附件";
                        String universahs = universal(fileInfos2, FileNamehs, fCaseid);
                        hwCaseSiteoper.setfGoodsannex(universahs);// sCMV.getfGoodsannex()
                    }
                    Integer insert = hwCaseSiteoperMapper.insert(hwCaseSiteoper);
                    if (insert != 1) {
                        throw new HWSystemException();
                    }
                }//有的修改
                if (hwCaseSiteopers.size() != 0) {
                    String fFirstviewannex = hwCaseSiteopers.get(0).getfFirstviewannex();//初检单 sCMV.getfFirstviewannex()
                    String fReviewannex = hwCaseSiteopers.get(0).getfReviewannex();//sCMV.getfReviewannex()
                    String fCopyannex = hwCaseSiteopers.get(0).getfTranannex();//移交单 sCMV.getfTranannex()
                    String fTranannex = hwCaseSiteopers.get(0).getfCopyannex(); //抄送单 sCMV.getfCopyannex()
                    String fFourlicannex = hwCaseSiteopers.get(0).getfFourlicannex();//“四证”照片 sCMV.getfFourlicannex()
                    String fGoodsannex = hwCaseSiteopers.get(0).getfGoodsannex();//sCMV.getfGoodsannex()
                    List<HwBaseAnnexesfile> list = hwBaseAnnexesfileList(fFirstviewannex);
                    List<HwBaseAnnexesfile> list2 = hwBaseAnnexesfileList(fReviewannex);
                    List<HwBaseAnnexesfile> list3 = hwBaseAnnexesfileList(fCopyannex);
                    List<HwBaseAnnexesfile> list4 = hwBaseAnnexesfileList(fTranannex);
                    List<HwBaseAnnexesfile> list5 = hwBaseAnnexesfileList(fFourlicannex);
                    List<HwBaseAnnexesfile> list6 = hwBaseAnnexesfileList(fGoodsannex);
                    hwBaseAnnexesFileDelete(list);
                    hwBaseAnnexesFileDelete(list2);
                    hwBaseAnnexesFileDelete(list3);
                    hwBaseAnnexesFileDelete(list4);
                    hwBaseAnnexesFileDelete(list5);
                    hwBaseAnnexesFileDelete(list6);
                    List<FileInfo> fileInfoList = sCMV.getfFirstviewannex();
                    String FileName = "初检单附件";
                    String universal = universal(fileInfoList, FileName, fCaseid);
                    hwCaseSiteoper.setfFirstviewannex(universal);//初检单 sCMV.getfFirstviewannex()
                    List<FileInfo> fileInfo = sCMV.getfReviewannex();
                    String FileNames = "复检单附件";
                    String universas = universal(fileInfo, FileNames, fCaseid);
                    hwCaseSiteoper.setfReviewannex(universas);//复检单 sCMV.getfReviewannex()
                    List<FileInfo> fileInfos = sCMV.getfTranannex();
                    String FileNamess = "移交单附件";
                    String universass = universal(fileInfos, FileNamess, fCaseid);
                    hwCaseSiteoper.setfTranannex(universass);// 移交单 sCMV.getfTranannex()
                    List<FileInfo> fileInfos1 = sCMV.getfCopyannex();
                    String FileNamesss = "抄送单附件";
                    String universasss = universal(fileInfos1, FileNamesss, fCaseid);
                    hwCaseSiteoper.setfCopyannex(universasss);//抄送单 sCMV.getfCopyannex()
                    List<FileInfo> fileInfos2 = sCMV.getfFourlicannex();
                    String FileNamessss = "四证照片附件";
                    String universassss = universal(fileInfos2, FileNamessss, fCaseid);
                    hwCaseSiteoper.setfFourlicannex(universassss); //“四证”照片 sCMV.getfFourlicannex()
                    List<FileInfo> fileInfos3 = sCMV.getfGoodsannex();
                    String FileNamehs = "货运单附件";
                    String universahs = universal(fileInfos3, FileNamehs, fCaseid);
                    hwCaseSiteoper.setfGoodsannex(universahs);// sCMV.getfGoodsannex()
                    Wrapper<HwCaseSiteoper> perWrapper = new EntityWrapper<HwCaseSiteoper>();
                    perWrapper.eq("F_SiteOperId", hwCaseSiteopers.get(0).getfSiteoperid()).eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                    Integer update1 = hwCaseSiteoperMapper.update(hwCaseSiteoper, perWrapper);
                    if (update1 != 1) {
                        return ResponeResultUtil.fail(HWSystemCode.FAIL);
                    }
                }//散货执法加入
                if ("SHZF".equals(sCMV.getVo().getfAjCasetype())){
                    //案件交警执法
                    Wrapper<HwCasePoliceoper> CasePoliceOPer = new EntityWrapper<HwCasePoliceoper>();
                    CasePoliceOPer.eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                    List<HwCasePoliceoper> hwCasePoliceopers = hwCasePoliceoperMapper.selectList(CasePoliceOPer);
                    HwCasePoliceoper hwCasePoliceoper = new HwCasePoliceoper();
                    String fPoliceoperid = RandomNumberUtil.getNumber();
                    hwCasePoliceoper.setfOverrunid(fOverruncode);//称重Id
                    hwCasePoliceoper.setfMainid(fCaseid);//案件Id
                    hwCasePoliceoper.setfPunishusername(sCMV.getVo().getfDrivername());//被处罚人 F_PartyName
                    hwCasePoliceoper.setfPunishuserphone(sCMV.getVo().getfDriverphone());//联系方式
                    if (hwCasePoliceopers.size() != 0) {
                        Wrapper<HwCasePoliceoper> casePol = new EntityWrapper<HwCasePoliceoper>();
                        String fPoliceOPer = hwCasePoliceopers.get(0).getfPoliceoperid();//F_PoliceOperId
                        casePol.eq("F_PoliceOperId", fPoliceOPer);
                        Integer update1 = hwCasePoliceoperMapper.update(hwCasePoliceoper, casePol);
                        if (update1 != 1) {
                            throw new HWSystemException();
                        }
                    } else {//没有添加
                        hwCasePoliceoper.setfPoliceoperid(fPoliceoperid);//主键
                        Integer insert = hwCasePoliceoperMapper.insert(hwCasePoliceoper);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }
                    // 源头倒查表
                    HwCaseSrccom hwCaseSrccom = new HwCaseSrccom();
                    Wrapper<HwCaseSrccom> caseSrccom = new EntityWrapper<HwCaseSrccom>();
                    caseSrccom.eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                    List<HwCaseSrccom> hwCaseSrccoms = hwCaseSrccomMapper.selectList(caseSrccom);
                    String Srccomid = RandomNumberUtil.getNumber();
                    hwCaseSrccom.setfOverrunid(fOverruncode);//称重Id
                    hwCaseSrccom.setfMainid(fCaseid);//案件Id
                    // hwCaseSrccom.setfTosrccomid(vo;//被处罚企业ID
                    hwCaseSrccom.setfTosrccomname(sCMV.getVo().getfSrcname());//被处罚源头企业名称
                    hwCaseSrccom.setfOperuserphone(sCMV.getVo().getfSrcphone());//联系方式
                    //有的话修改
                    if (hwCaseSrccoms.size() != 0) {
                        String fSrccomid = hwCaseSrccoms.get(0).getfSrccomid();
                        Wrapper<HwCaseSrccom> perWrapper = new EntityWrapper<HwCaseSrccom>();
                        perWrapper.eq("F_SrcComId", fSrccomid);
                        Integer update1 = hwCaseSrccomMapper.update(hwCaseSrccom, perWrapper);
                        if (update1 != 1) {
                            throw new HWSystemException();
                        }
                    } else { //没有添加
                        hwCaseSrccom.setfSrccomid(Srccomid);//
                        Integer insert = hwCaseSrccomMapper.insert(hwCaseSrccom);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }
                }
                //F_AJ_CaseType 案件类型（鲜活农产品-NCPZF、散货-SHZF、不可解体-BKJTZF）
                String ajCaseType = sCMV.getVo().getfAjCasetype();
                //HW_Case_FileConfig  文书基础配置表
                Wrapper<HwCaseFileconfig> fileconfig = new EntityWrapper<HwCaseFileconfig>();
                fileconfig.eq("F_FileType", ajCaseType);
                List<HwCaseFileconfig> hwCaseFileconfigs = hwCaseFileconfigMapper.selectList(fileconfig);
                //案件文书上传表
                Wrapper<HwCaseFile> caseFile = new EntityWrapper<HwCaseFile>();
                caseFile.eq("F_MainId", fCaseid);
                List<HwCaseFile> fileList = hwCaseFileMapper.selectList(caseFile);
                if (fileList.size() != 0) {
                    for (HwCaseFile hwCaseFile : fileList) {
                        Integer integer = hwCaseFileMapper.deleteById(hwCaseFile.getfFileid());
                        if (integer != 1) {
                            throw new HWSystemException();
                        }
                    }
                    for (HwCaseFileconfig hwCaseFileconfig : hwCaseFileconfigs) {
                        HwCaseFile hwCaseFile = new HwCaseFile();
                        hwCaseFile.setfFileid(RandomNumberUtil.getNumber());//	主键
                        hwCaseFile.setfMainid(fCaseid);// 案件Id
                        hwCaseFile.setfPagecode(hwCaseFileconfig.getfPagecode());// 文书页编码
                        hwCaseFile.setfUploadflag(0);// 0-未上传；1-已上传
                        Integer insert = hwCaseFileMapper.insert(hwCaseFile);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }
                } else {
                    //批量插入
                    for (HwCaseFileconfig hwCaseFileconfig : hwCaseFileconfigs) {
                        HwCaseFile hwCaseFile = new HwCaseFile();
                        hwCaseFile.setfFileid(RandomNumberUtil.getNumber());//	主键
                        hwCaseFile.setfMainid(fCaseid);// 案件Id
                        hwCaseFile.setfPagecode(hwCaseFileconfig.getfPagecode());// 文书页编码
                        hwCaseFile.setfUploadflag(0);// 0-未上传；1-已上传
                        Integer insert = hwCaseFileMapper.insert(hwCaseFile);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }
                }
				HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
				hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
				hwCommandWorkflow.setWorkflowModule(presentWorkflow.getWorkflowModule());
				hwCommandWorkflow.setWorkflowType(presentWorkflow.getWorkflowType());
				hwCommandWorkflow.setWorkflowCode(presentWorkflow.getWorkflowCode());
				hwCommandWorkflow.setWorkflowCodename(presentWorkflow.getWorkflowCodename());
				hwCommandWorkflow.setCommandworkflowButtonname(sCMV.getButtonName());
				hwCommandWorkflow.setfAccount(sCMV.getfAccount());
				hwCommandWorkflow.setfFromdepcode(sCMV.getfFromdepcode());
				hwCommandWorkflow.setfFromdepname(sCMV.getfFromdepname());
				hwCommandWorkflow.setCommandworkflowDatatime(new Date());
//				hwCommandWorkflow.setCommandworkflowContent(sCMV.getTaskContent());
                //                 hwCommandWorkflow.setfAnnexes();
				hwCommandWorkflow.setObjectId(sCMV.getVo().getfCaseid());//有什么用字段
//                 hwCommandWorkflow.setfAnnexes();
				hwCommandWorkflow.setWorkflowNextcode(presentWorkflow.getWorkflowNextcode());
				hwCommandWorkflow.setWorkflowNextcodename(presentWorkflow.getWorkflowNextcodename());
				// (4.2)各审批操作过程表，插入内容：全部，对应异地复检处理
				// 向各阶段审批操作过程表插入数据
				boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
				if (success == false) {
					// 事务回滚
					throw new HWSystemException();
				}
            }
        }//案件暂存
        if ("02".equals(fAjCrtstep)) {
            long beginlong = new Long(sCMV.getfAjCreatetime());
            if ("GR".equals(sCMV.getVo().getfCzOrgtype())) {
                sCMV.getVo().setfCzParty(sCMV.getVo().getfPartyname());
                sCMV.getVo().setfAjOwner("公民");

            }
            if ("GS".equals(sCMV.getVo().getfCzOrgtype())) { //单位
                sCMV.getVo().setfAjOwner("法人及其它组织");
                sCMV.getVo().setfCzParty(sCMV.getVo().getfCompanyname());
            }
            //修改立案的内容
            HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(fCaseid);
            sCMV.getVo().setFAjCreatetime(new Timestamp(beginlong));//new Timestamp(System.curr
            String getfAjCrtstep = "01"; //Flow_Code
            String getfAjCasecode = sCMV.getVo().getFlowCode();
            HwBaseWorkflow presentWorkflow = baseWorkflowService.getPresentWorkflow(getfAjCrtstep, getfAjCasecode);
            sCMV.getVo().setfAjCrtstep(presentWorkflow.getWorkflowNextcode());
            Wrapper<HwCaseMain> stationStorywrapper = new EntityWrapper<HwCaseMain>();
            stationStorywrapper.eq("F_CaseId", fCaseid).eq("F_OverrunID", fOverruncode);
            Integer update = hwCaseMainMapper.update(sCMV.getVo(), stationStorywrapper);
            if (update != 0) {
                HwCaseSiteoper hwCaseSiteoper = new HwCaseSiteoper();
                Wrapper<HwCaseSiteoper> caseSiteOPerWrapper = new EntityWrapper<HwCaseSiteoper>();
                caseSiteOPerWrapper.eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                List<HwCaseSiteoper> hwCaseSiteopers = hwCaseSiteoperMapper.selectList(caseSiteOPerWrapper);
                //案件站点办理
                String code = RandomNumberUtil.getNumber();
                hwCaseSiteoper.setfOverrunid(fOverruncode);// 称重Id
                hwCaseSiteoper.setfMainid(fCaseid);//案件Id
                //没有添加
                if (hwCaseSiteopers.size() == 0) {
                    hwCaseSiteoper.setfSiteoperid(code); //
                    List<FileInfo> fileInfoList = sCMV.getfFirstviewannex();
                    String FileName = "初检单附件";
                    String universal = universal(fileInfoList, FileName, fCaseid);
                    hwCaseSiteoper.setfFirstviewannex(universal);//初检单 sCMV.getfFirstviewannex()
                    List<FileInfo> fileInfo = sCMV.getfReviewannex();
                    String FileNames = "复检单附件";
                    String universas = universal(fileInfo, FileNames, fCaseid);
                    hwCaseSiteoper.setfReviewannex(universas);//复检单 sCMV.getfReviewannex()
                    List<FileInfo> fileInfos = sCMV.getfTranannex();
                    String FileNamess = "移交单附件";
                    String universass = universal(fileInfos, FileNamess, fCaseid);
                    hwCaseSiteoper.setfTranannex(universass);// 移交单 sCMV.getfTranannex()
                    List<FileInfo> fileInfos1 = sCMV.getfCopyannex();
                    String FileNamesss = "抄送单附件";
                    String universasss = universal(fileInfos1, FileNamesss, fCaseid);
                    hwCaseSiteoper.setfCopyannex(universasss);//抄送单 sCMV.getfCopyannex()
                    List<FileInfo> fileInfos2 = sCMV.getfFourlicannex();
                    String FileNamessss = "四证照片附件";
                    String universassss = universal(fileInfos2, FileNamessss, fCaseid);
                    hwCaseSiteoper.setfFourlicannex(universassss); //“四证”照片 sCMV.getfFourlicannex()
                    List<FileInfo> fileInfos3 = sCMV.getfGoodsannex();
                    String FileNamehs = "货运单附件";
                    String universahs = universal(fileInfos3, FileNamehs, fCaseid);
                    hwCaseSiteoper.setfGoodsannex(universahs);// sCMV.getfGoodsannex()
                    Integer insert = hwCaseSiteoperMapper.insert(hwCaseSiteoper);
                    if (insert != 1) {
                        throw new HWSystemException();
                    }
                }//有的修改
                if (hwCaseSiteopers.size() != 0) {
                    String fFirstviewannex = hwCaseSiteopers.get(0).getfFirstviewannex();//初检单 sCMV.getfFirstviewannex()
                    String fReviewannex = hwCaseSiteopers.get(0).getfReviewannex();//sCMV.getfReviewannex()
                    String fCopyannex = hwCaseSiteopers.get(0).getfTranannex();//移交单 sCMV.getfTranannex()
                    String fTranannex = hwCaseSiteopers.get(0).getfCopyannex(); //抄送单 sCMV.getfCopyannex()
                    String fFourlicannex = hwCaseSiteopers.get(0).getfFourlicannex();//“四证”照片 sCMV.getfFourlicannex()
                    String fGoodsannex = hwCaseSiteopers.get(0).getfGoodsannex();//sCMV.getfGoodsannex()
                    List<HwBaseAnnexesfile> list = hwBaseAnnexesfileList(fFirstviewannex);
                    List<HwBaseAnnexesfile> list2 = hwBaseAnnexesfileList(fReviewannex);
                    List<HwBaseAnnexesfile> list3 = hwBaseAnnexesfileList(fCopyannex);
                    List<HwBaseAnnexesfile> list4 = hwBaseAnnexesfileList(fTranannex);
                    List<HwBaseAnnexesfile> list5 = hwBaseAnnexesfileList(fFourlicannex);
                    List<HwBaseAnnexesfile> list6 = hwBaseAnnexesfileList(fGoodsannex);

                    hwBaseAnnexesFileDelete(list);
                    hwBaseAnnexesFileDelete(list2);
                    hwBaseAnnexesFileDelete(list3);
                    hwBaseAnnexesFileDelete(list4);
                    hwBaseAnnexesFileDelete(list5);
                    hwBaseAnnexesFileDelete(list6);
                    List<FileInfo> fileInfoList = sCMV.getfFirstviewannex();
                    String FileName = "初检单附件";
                    String universal = universal(fileInfoList, FileName, fCaseid);
                    hwCaseSiteoper.setfFirstviewannex(universal);//初检单 sCMV.getfFirstviewannex()
                    List<FileInfo> fileInfo = sCMV.getfReviewannex();
                    String FileNames = "复检单附件";
                    String universas = universal(fileInfo, FileNames, fCaseid);
                    hwCaseSiteoper.setfReviewannex(universas);//复检单 sCMV.getfReviewannex()
                    List<FileInfo> fileInfos = sCMV.getfTranannex();
                    String FileNamess = "移交单附件";
                    String universass = universal(fileInfos, FileNamess, fCaseid);
                    hwCaseSiteoper.setfTranannex(universass);// 移交单 sCMV.getfTranannex()
                    List<FileInfo> fileInfos1 = sCMV.getfCopyannex();
                    String FileNamesss = "抄送单附件";
                    String universasss = universal(fileInfos1, FileNamesss, fCaseid);
                    hwCaseSiteoper.setfCopyannex(universasss);//抄送单 sCMV.getfCopyannex()
                    List<FileInfo> fileInfos2 = sCMV.getfFourlicannex();
                    String FileNamessss = "四证照片附件";
                    String universassss = universal(fileInfos2, FileNamessss, fCaseid);
                    hwCaseSiteoper.setfFourlicannex(universassss); //“四证”照片 sCMV.getfFourlicannex()
                    List<FileInfo> fileInfos3 = sCMV.getfGoodsannex();
                    String FileNamehs = "货运单附件";
                    String universahs = universal(fileInfos3, FileNamehs, fCaseid);
                    hwCaseSiteoper.setfGoodsannex(universahs);// sCMV.getfGoodsannex()
                    Wrapper<HwCaseSiteoper> perWrapper = new EntityWrapper<HwCaseSiteoper>();
                    perWrapper.eq("F_SiteOperId", hwCaseSiteopers.get(0).getfSiteoperid()).eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                    Integer update1 = hwCaseSiteoperMapper.update(hwCaseSiteoper, perWrapper);
                    if (update1 != 1) {
                        return ResponeResultUtil.fail(HWSystemCode.FAIL);
                    }
                }
                if ("SHZF".equals(sCMV.getVo().getfAjCasetype())){
                    //案件交警执法
                    Wrapper<HwCasePoliceoper> CasePoliceOPer = new EntityWrapper<HwCasePoliceoper>();
                    CasePoliceOPer.eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                    List<HwCasePoliceoper> hwCasePoliceopers = hwCasePoliceoperMapper.selectList(CasePoliceOPer);
                    HwCasePoliceoper hwCasePoliceoper = new HwCasePoliceoper();
                    String fPoliceoperid = RandomNumberUtil.getNumber();
                    hwCasePoliceoper.setfOverrunid(fOverruncode);//称重Id
                    hwCasePoliceoper.setfMainid(fCaseid);//案件Id
                    hwCasePoliceoper.setfPunishusername(sCMV.getVo().getfDrivername());//被处罚人 F_PartyName
                    hwCasePoliceoper.setfPunishuserphone(sCMV.getVo().getfDriverphone());//联系方式
                    if (hwCasePoliceopers.size() != 0) {
                        Wrapper<HwCasePoliceoper> casePol = new EntityWrapper<HwCasePoliceoper>();
                        String fPoliceOPer = hwCasePoliceopers.get(0).getfPoliceoperid();//F_PoliceOperId
                        casePol.eq("F_PoliceOperId", fPoliceOPer);
                        Integer update1 = hwCasePoliceoperMapper.update(hwCasePoliceoper, casePol);
                        if (update1 != 1) {
                            throw new HWSystemException();
                        }
                    } else {//没有添加
                        hwCasePoliceoper.setfPoliceoperid(fPoliceoperid);//主键
                        Integer insert = hwCasePoliceoperMapper.insert(hwCasePoliceoper);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }
                    // 源头倒查表
                    HwCaseSrccom hwCaseSrccom = new HwCaseSrccom();
                    Wrapper<HwCaseSrccom> caseSrccom = new EntityWrapper<HwCaseSrccom>();
                    caseSrccom.eq("F_OverrunID", fOverruncode).eq("F_MainId", fCaseid);
                    List<HwCaseSrccom> hwCaseSrccoms = hwCaseSrccomMapper.selectList(caseSrccom);
                    String Srccomid = RandomNumberUtil.getNumber();
                    hwCaseSrccom.setfOverrunid(fOverruncode);//称重Id
                    hwCaseSrccom.setfMainid(fCaseid);//案件Id
                    // hwCaseSrccom.setfTosrccomid(vo;//被处罚企业ID
                    hwCaseSrccom.setfTosrccomname(sCMV.getVo().getfSrcname());//被处罚源头企业名称
                    hwCaseSrccom.setfOperuserphone(sCMV.getVo().getfSrcphone());//联系方式
                    //有的话修改
                    if (hwCaseSrccoms.size() != 0) {
                        String fSrccomid = hwCaseSrccoms.get(0).getfSrccomid();
                        Wrapper<HwCaseSrccom> perWrapper = new EntityWrapper<HwCaseSrccom>();
                        perWrapper.eq("F_SrcComId", fSrccomid);
                        Integer update1 = hwCaseSrccomMapper.update(hwCaseSrccom, perWrapper);
                        if (update1 != 1) {
                            throw new HWSystemException();
                        }
                    } else { //没有添加
                        hwCaseSrccom.setfSrccomid(Srccomid);//
                        Integer insert = hwCaseSrccomMapper.insert(hwCaseSrccom);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }

                }
                //F_AJ_CaseType 案件类型（鲜活农产品-NCPZF、散货-SHZF、不可解体-BKJTZF）
                String ajCaseType = sCMV.getVo().getfAjCasetype();
                //HW_Case_FileConfig  文书基础配置表
                Wrapper<HwCaseFileconfig> fileconfig = new EntityWrapper<HwCaseFileconfig>();
                fileconfig.eq("F_FileType", ajCaseType);
                List<HwCaseFileconfig> hwCaseFileconfigs = hwCaseFileconfigMapper.selectList(fileconfig);
                //案件文书上传表
                Wrapper<HwCaseFile> caseFile = new EntityWrapper<HwCaseFile>();
                caseFile.eq("F_MainId", fCaseid);
                List<HwCaseFile> fileList = hwCaseFileMapper.selectList(caseFile);
                if (fileList.size() != 0) {
                    for (HwCaseFile hwCaseFile1 : fileList) {
                        Integer integer = hwCaseFileMapper.deleteById(hwCaseFile1.getfFileid());
                        if (integer != 1) {
                            throw new HWSystemException();
                        }
                    }
                    for (HwCaseFileconfig hwCaseFileconfig : hwCaseFileconfigs) {
                        HwCaseFile hwCaseFile = new HwCaseFile();
                        hwCaseFile.setfFileid(RandomNumberUtil.getNumber());//	主键
                        hwCaseFile.setfMainid(fCaseid);// 案件Id
                        hwCaseFile.setfPagecode(hwCaseFileconfig.getfPagecode());// 文书页编码
                        hwCaseFile.setfUploadflag(0);// 0-未上传；1-已上传
                        Integer insert = hwCaseFileMapper.insert(hwCaseFile);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }

                } else {
                    //批量插入
                    for (HwCaseFileconfig hwCaseFileconfig : hwCaseFileconfigs) {
                        HwCaseFile hwCaseFile = new HwCaseFile();
                        hwCaseFile.setfFileid(RandomNumberUtil.getNumber());//	主键
                        hwCaseFile.setfMainid(fCaseid);// 案件Id
                        hwCaseFile.setfPagecode(hwCaseFileconfig.getfPagecode());// 文书页编码
                        hwCaseFile.setfUploadflag(0);// 0-未上传；1-已上传
                        Integer insert = hwCaseFileMapper.insert(hwCaseFile);
                        if (insert != 1) {
                            throw new HWSystemException();
                        }
                    }
                }
                HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
                hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
                hwCommandWorkflow.setWorkflowModule(presentWorkflow.getWorkflowModule());
                hwCommandWorkflow.setWorkflowType(presentWorkflow.getWorkflowType());
                hwCommandWorkflow.setWorkflowCode(presentWorkflow.getWorkflowCode());
                hwCommandWorkflow.setWorkflowCodename(presentWorkflow.getWorkflowCodename());
                hwCommandWorkflow.setCommandworkflowButtonname(sCMV.getButtonName());
                hwCommandWorkflow.setfAccount(sCMV.getfAccount());
                hwCommandWorkflow.setfFromdepcode(sCMV.getfFromdepcode());
                hwCommandWorkflow.setfFromdepname(sCMV.getfFromdepname());
                hwCommandWorkflow.setCommandworkflowDatatime(new Date());
//                hwCommandWorkflow.setCommandworkflowContent(sCMV.getTaskContent());
                hwCommandWorkflow.setObjectId(sCMV.getVo().getfCaseid());//有什么用字段
                hwCommandWorkflow.setWorkflowNextcode(presentWorkflow.getWorkflowNextcode());
                hwCommandWorkflow.setWorkflowNextcodename(presentWorkflow.getWorkflowNextcodename());
                // (4.2)各审批操作过程表，插入内容：全部，对应异地复检处理
                // 向各阶段审批操作过程表插入数据
                boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
                if (success == false) {
                    // 事务回滚
                    throw new HWSystemException();
                }
            }
        }
        return ResponeResultUtil.success(HWSystemCode.SUCCESS);
    }

    /**
     * 超限站（执法监管）---修改
     *
     * @param
     * @return put on record
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class, RuntimeException.class,
            HWSystemException.class})
    public Map<String, Object> revamp(StationCaseFileVo vo) {
        List<HwCaseFile> fileVo = vo.getFileVo();

        for (HwCaseFile hwCaseFile : fileVo) {
            if (hwCaseFile.getfFilesrc()!=""){
                Wrapper<HwCaseFile> caseFile = new EntityWrapper<HwCaseFile>();
                HwCaseFile hwCaseFile1 = new HwCaseFile();
                hwCaseFile1.setfUploadflag(1); //F_UploadFlag 0-未上传；1-已上传
                hwCaseFile1.setfFilesrc(hwCaseFile.getfFilesrc()); //F_FileSrc 文件路径，多文件以";"分割
                hwCaseFile1.setfUploaduserid(vo.getfUploaduserid());// F_UploadUserId	varchar(50)		上传人Id
                hwCaseFile1.setfUploaddeptcode(vo.getfUploaddeptcode());//  F_UploadDeptCode	varchar(50)		上传人所在机构
                hwCaseFile1.setfUploadtime(new Timestamp(System.currentTimeMillis()));//  F_UploadTime	datetime		上传时间
                caseFile.eq("F_FileId", hwCaseFile.getfFileid());
                Integer update = hwCaseFileMapper.update(hwCaseFile1, caseFile);
                if (update != 1) {
                    throw new HWSystemException();
                }
            }

        }
        return ResponeResultUtil.success(HWSystemCode.SUCCESS);
    }


    /**
     * 超限站（执法监管）---案件文书上传
     *
     * @param
     * @return put on record
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class, RuntimeException.class,
            HWSystemException.class})
    public Map<String, Object> uploadDocuments(HwCaseMain vo) {
        String fCaseid = vo.getfCaseid();//
        String ajCasetype = vo.getfAjCasetype();//
        List<Map<String, Object>> maps = hwCaseFileMapper.dyGetUserList(fCaseid, ajCasetype);
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, maps);
    }

    /**
     * 超限站（执法监管）---放行确认
     *
     * @param vo
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class, RuntimeException.class,
            HWSystemException.class})
    public Map<String, Object> releaseConfirmation(StepInfoVO vo) {
        String date = vo.getfAjGostatedate();
        String fCaseid = vo.getfCaseid();//
        String ajCasetype = vo.getfAjCasetype();//
        List<Map<String, Object>> list = hwCaseFileMapper.uploadingFinish(fCaseid, ajCasetype);
        boolean file = true;
        for (Map<String, Object> map : list) {
            Integer f_uploadFlag = (Integer)map.get("F_UploadFlag");
            Integer f_uploadCheck =(Integer) map.get("F_UploadCheck");
            if(f_uploadCheck==1){
            if(f_uploadFlag!=1){
                file=false;
              }
            }
        }
        HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(fCaseid);

        Integer integer = hwCaseMain.getfAjGostate();
        String fAjCrtstep = hwCaseMain.getfAjCrtstep(); //F_AJ_GoState=0 fAjCasetype
        String ajCasetype1 = hwCaseMain.getfAjCasetype();
        //按钮显示条件：待放行确认且放行类型为正常的案件；(F_AJ_CrtStep =05 and F_AJ_GoState=0)
        //.【放行】需验证必传文书是否上传完毕、不满足提示“该案件文书未按照必传要求上传！”；
        if ("05".equals(fAjCrtstep) && integer == 0) {
            if (file) {
                HwBaseWorkflow presentWorkflow = baseWorkflowService.getPresentWorkflow(fAjCrtstep, ajCasetype1);
                Wrapper<HwCaseMain> fwrapper = new EntityWrapper<HwCaseMain>();
                fwrapper.eq("F_CaseId", fCaseid);
                HwCaseMain hCaseMain = new HwCaseMain();
                long beginlong = new Long(date);
                hCaseMain.setfAjCrtstep(presentWorkflow.getWorkflowNextcode());
//				hCaseMain.setfAjGostate(0);        //F_AJ_GoStateDate F_AJ_GoState
                Integer update = hwCaseMainMapper.update(hCaseMain, fwrapper);
                if (update != 1) {
                    throw new HWSystemException();
                }
                // 附件id
//                String remarkFolderId = RandomNumberUtil.getNumber();
                String fileId = RandomNumberUtil.getNumber();
                //更新放行时间、情况说明 案件站点办理  HW_Case_SiteOper 案件站点办理
                //情况说明附件 不必传
                List<FileInfo> fileInfoList = vo.getFileInfoList();
                int i = 0;
                for (FileInfo fileInfo : fileInfoList) {
                    ++i;
                    HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
                    hwBaseAnnexesfile.setFileMoudletype("ZFJGFILE执法监管");
                    hwBaseAnnexesfile.setFileName("放行确认附件" + String.valueOf(i));
                    hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
                    hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
                    hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
                    hwBaseAnnexesfile.setfCreateuserid(vo.getLoginUser());
                    hwBaseAnnexesfile.setfFolderid(fileId);
                    hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
                    hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
                    hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
                    Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
                    if (insert != 1) {
                        throw new HWSystemException();
                    }
                }
                String fOverrunid = hwCaseMain.getfOverrunid();
                HwCaseSiteoper hwCaseSiteoper = new HwCaseSiteoper();
                hwCaseSiteoper.setfAjGostatedate(new Date(beginlong));
                hwCaseSiteoper.setfAjGocontent(vo.getfAjGocontent());
                if (fileInfoList.size()!=0){
                    hwCaseSiteoper.setfAjGofile(fileId); //fAjGofile
                }
                Wrapper<HwCaseSiteoper> Siteoperwrapper = new EntityWrapper<HwCaseSiteoper>();
                Siteoperwrapper.eq("F_OverrunID", fOverrunid).eq("F_MainId", fCaseid);
                Integer update1 = hwCaseSiteoperMapper.update(hwCaseSiteoper, Siteoperwrapper);
                if (update1 != 1) {
                    throw new HWSystemException();
                }
                HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
                hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
                hwCommandWorkflow.setWorkflowModule(presentWorkflow.getWorkflowModule());
                hwCommandWorkflow.setWorkflowType(presentWorkflow.getWorkflowType());
                hwCommandWorkflow.setWorkflowCode(presentWorkflow.getWorkflowCode());
                hwCommandWorkflow.setWorkflowCodename(presentWorkflow.getWorkflowCodename());
                hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
                hwCommandWorkflow.setfAccount(vo.getfAccount());
                hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
                hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
                hwCommandWorkflow.setCommandworkflowDatatime(new Date());
                hwCommandWorkflow.setCommandworkflowContent(vo.getfAjGocontent());
                hwCommandWorkflow.setObjectId(fCaseid);
                if (fileInfoList.size()!=0){
                    hwCommandWorkflow.setfAnnexes(fileId);
                }
                hwCommandWorkflow.setWorkflowNextcode(presentWorkflow.getWorkflowNextcode());
                hwCommandWorkflow.setWorkflowNextcodename(presentWorkflow.getWorkflowNextcodename());
                // 向各阶段审批操作过程表插入数据
                boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
                if (success == false) {
                    throw new HWSystemException();
                }
            } else {
                //该案件文书未按照必传要求上传！
                return ResponeResultUtil.success(HWSystemCode.UPLOADING);
            }
        } else {
            //提交条件再次判断，不满足提示“该信息不能进行放行确认！
            return ResponeResultUtil.success(HWSystemCode.RELEAS_CONFIRMATION);
        }
        return ResponeResultUtil.success(HWSystemCode.SUCCESS);
    }

    /**
     * 超限站（执法监管）---放行说明
     *
     * @param vo
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class, RuntimeException.class,
            HWSystemException.class})
    public Map<String, Object> releaseInstructions(StepInfoVO vo) {
        //类型，只查扣未立案（无牌|当事人不来|其他）、查扣已立案（套牌|无牌）
        String fAjGotype = vo.getfAjGotype();
        //选择（年-月-日）（必填）
        String date = vo.getfAjGostatedate();
        long beginlong = new Long(date);
        String fCaseid = vo.getfCaseid();//
        String ajCasetype = vo.getfAjCasetype();//
        HwCaseMain hwCaseMain = hwCaseMainMapper.selectById(fCaseid);
        //F_AJ_CrtStep =05 and F_AJ_GoState=1
        //		//条件
        if ("05".equals(hwCaseMain.getfAjCrtstep()) && hwCaseMain.getfAjGostate() == 1) {
                String fAjCrtstep = hwCaseMain.getfAjCrtstep(); //F_AJ_GoState=0 fAjCasetype
                String ajCasetype1 = hwCaseMain.getfAjCasetype();
                HwBaseWorkflow presentWorkflow = baseWorkflowService.getPresentWorkflow(fAjCrtstep, ajCasetype1);
                Wrapper<HwCaseMain> fwrapper = new EntityWrapper<HwCaseMain>();
                fwrapper.eq("F_CaseId", fCaseid);
                HwCaseMain hCaseMain = new HwCaseMain();
                hCaseMain.setfAjCrtstep(presentWorkflow.getWorkflowNextcode());
//				hCaseMain.setfAjGostate(0);        //F_AJ_GoStateDate F_AJ_GoState
                Integer update = hwCaseMainMapper.update(hCaseMain, fwrapper);
                if (update != 1) {
                    throw new HWSystemException();
                }
                // 附件id
                String fileId = RandomNumberUtil.getNumber();
                //更新放行时间、情况说明 案件站点办理  HW_Case_SiteOper 案件站点办理
                String fOverrunid = hwCaseMain.getfOverrunid();
                HwCaseSiteoper hwCaseSiteoper = new HwCaseSiteoper();
                hwCaseSiteoper.setfSiteoperid(fileId);
                hwCaseSiteoper.setfOverrunid(fOverrunid);
                hwCaseSiteoper.setfMainid(fCaseid);
                hwCaseSiteoper.setfAjGostatedate(new Date(beginlong));
                hwCaseSiteoper.setfAjGocontent(vo.getfAjGocontent());
                hwCaseSiteoper.setfAjGofile(fileId); //fAjGofile
                hwCaseSiteoper.setfAjGotype(fAjGotype);
//                Wrapper<HwCaseSiteoper> Siteoperwrapper = new EntityWrapper<HwCaseSiteoper>();
//                Siteoperwrapper.eq("F_OverrunID", fOverrunid).eq("F_MainId", fCaseid);
                Integer update1 = hwCaseSiteoperMapper.insert(hwCaseSiteoper);
                if (update1 != 1) {
                    throw new HWSystemException();
                }
                //情况说明附件 不必传
                List<FileInfo> fileInfoList = vo.getFileInfoList();
                int i = 0;
                for (FileInfo fileInfo : fileInfoList) {
                    ++i;
                    HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
                    hwBaseAnnexesfile.setFileMoudletype("ZFJGFILE执法监管");
                    hwBaseAnnexesfile.setFileName("放行说明附件" + String.valueOf(i));
                    hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
                    hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
                    hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
                    hwBaseAnnexesfile.setfCreateuserid(vo.getLoginUser());
                    hwBaseAnnexesfile.setfFolderid(fileId);
                    hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
                    hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
                    hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
                    Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
                    if (insert != 1) {
                        throw new HWSystemException();
                    }
                }
                HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
                hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
                hwCommandWorkflow.setWorkflowModule(presentWorkflow.getWorkflowModule());
                hwCommandWorkflow.setWorkflowType(presentWorkflow.getWorkflowType());
                hwCommandWorkflow.setWorkflowCode(presentWorkflow.getWorkflowCode());
                hwCommandWorkflow.setWorkflowCodename(presentWorkflow.getWorkflowCodename());
                hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
                hwCommandWorkflow.setfAccount(vo.getLoginUser());
                hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
                hwCommandWorkflow.setfFromdepname(vo.getDeptName());
                hwCommandWorkflow.setCommandworkflowDatatime(new Date());
                hwCommandWorkflow.setCommandworkflowContent(vo.getfAjGocontent());
                hwCommandWorkflow.setObjectId(fCaseid);
                hwCommandWorkflow.setfAnnexes(fileId);
                hwCommandWorkflow.setWorkflowNextcode(presentWorkflow.getWorkflowNextcode());
                hwCommandWorkflow.setWorkflowNextcodename(presentWorkflow.getWorkflowNextcodename());
                // 向各阶段审批操作过程表插入数据
                boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
                if (success == false) {
                    throw new HWSystemException();
                }
        } else {
            //提交条件再次判断，不满足提示“该信息不能进行放行确认！
            return ResponeResultUtil.success(HWSystemCode.RELEAS_CONFIRMATION);
        }
        return ResponeResultUtil.success(HWSystemCode.SUCCESS);
    }


    public Map<String, Object> findFile(String caseid) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        HwCaseSiteoper entity = new HwCaseSiteoper();
        entity.setfMainid(caseid);
        HwCaseSiteoper selectOne = hwCaseSiteoperMapper.selectOne(entity);
        if(selectOne!=null){
        	  HashMap<String, String> fileIds = new HashMap<String, String>();
              fileIds.put("F_FirstViewAnnex", selectOne.getfFirstviewannex());
              fileIds.put("F_ReViewAnnex", selectOne.getfReviewannex());
              fileIds.put("F_TranAnnex", selectOne.getfTranannex());
              fileIds.put("F_CopyAnnex", selectOne.getfCopyannex());
              fileIds.put("F_GoodsAnnex", selectOne.getfGoodsannex());
              fileIds.put("F_FourLicAnnex", selectOne.getfFourlicannex());

//      		根据folderid取附件集合
              for (String key : fileIds.keySet()) {
                  String fileid = fileIds.get(key);
                  Wrapper<HwBaseAnnexesfile> wrapper = new EntityWrapper<HwBaseAnnexesfile>();
                  wrapper.eq("F_FolderId", fileid);
                  List<HwBaseAnnexesfile> selectList = hwBaseAnnexesfileMapper.selectList(wrapper);
                  result.put(key, selectList);
              }
        }
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, result);
    }

    /**
     * 附件上传
     *
     * @return
     */
//	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class, RuntimeException.class,
//			HWSystemException.class})
    public String universal(List<FileInfo> fileInfoList, String string, String fCaseid) {
        String fileId = RandomNumberUtil.getNumber();
        //情况说明附件 不必传
        int i = 0;
        for (FileInfo fileInfo : fileInfoList) {
            ++i;
            HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
            hwBaseAnnexesfile.setFileMoudletype("ZFJGFILE执法监管");
            hwBaseAnnexesfile.setFileName(string + String.valueOf(i));
            hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
            hwBaseAnnexesfile.setfFolderid(fileId);
            hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
//			hwBaseAnnexesfile.setfCreateusername(vo.getfAccount());
//			hwBaseAnnexesfile.setfCreateuserid(vo.getLoginUser());
            hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
            hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
            hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
            Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
            if (insert != 1) {
                throw new HWSystemException();
            }
        }
        return fileId;
    }

    public List<HwBaseAnnexesfile> hwBaseAnnexesfileList(String fCaseid) {
        Wrapper<HwBaseAnnexesfile> Siteoperwrapper = new EntityWrapper<HwBaseAnnexesfile>();
        Siteoperwrapper.eq("F_FolderId", fCaseid);
        List<HwBaseAnnexesfile> list = hwBaseAnnexesfileMapper.selectList(Siteoperwrapper);
        return list;
    }

    //
//	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class, RuntimeException.class,
//			HWSystemException.class})
    public int hwBaseAnnexesFileDelete(List<HwBaseAnnexesfile> list) {
        for (HwBaseAnnexesfile hwBaseAnnexesfile : list) {
            Integer integer = hwBaseAnnexesfileMapper.deleteById(hwBaseAnnexesfile.getFileId());
            if (integer != 1) {
                throw new HWSystemException();
            }
        }
        return 1;
    }
}
